import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:largefriends/res/lf_color.dart';

import '../../../entity/entities/chat_new_message_entity.dart';
import '../../../service/manager/lf_event_helper.dart';
import '../../../res/lf_fonts.dart';
import '../../../res/lf_text_style.dart';
import '../../../res/strings/lf_strings.dart';
import 'custom_pop_up_menu.dart';

Widget getMenuWidget({
  required ChatNewMessageEntity data,
  required Widget child,
  required bool isSender,
  required Function recall,
  required Function report,
  required Function reply,
  required bool canShowMenu,
  bool isTextMessage = false,
}) {
  if (canShowMenu == false) {
    return child;
  }

  CustomPopupMenuController customPopupMenuController =
      CustomPopupMenuController();

  List<Widget> children = List.empty(growable: true);
  if (isSender) {
    children.add(GestureDetector(
      onTap: () async {
        LfEventHelper().getEvent().fire(DismissMenuEvent());
        recall.call();
      },
      behavior: HitTestBehavior.opaque,
      child: Container(
        decoration: BoxDecoration(
          color: colorFEFEFE,
          borderRadius: BorderRadius.all(Radius.circular(4.r)),
        ),
        padding: EdgeInsets.symmetric(vertical: 6.h, horizontal: 10.w),
        child: Text(
          strUnsend.tr,
          style: lfTextStyle(
              sp: 14.sp, fontFamily: fontMedium, color: Colors.white),
        ),
      ),
    ));
  } else {
    children.add(GestureDetector(
      onTap: () async {
        LfEventHelper().getEvent().fire(DismissMenuEvent());
        report.call();
      },
      behavior: HitTestBehavior.opaque,
      child: Container(
        padding: EdgeInsets.symmetric(vertical: 6.h, horizontal: 10.w),
        child: Text(
          strReport.tr.toUpperCase(),
          style: lfTextStyle(
              sp: 14.sp, fontFamily: fontMedium, color: Colors.white),
        ),
      ),
    ));
    if (isTextMessage) {
      children.add(GestureDetector(
        onTap: () async {
          LfEventHelper().getEvent().fire(DismissMenuEvent());
          reply.call();
        },
        behavior: HitTestBehavior.opaque,
        child: Container(
          padding: EdgeInsets.symmetric(vertical: 6.h, horizontal: 10.w),
          child: Text(
            strReply.tr,
            style: lfTextStyle(
                sp: 14.sp, fontFamily: fontMedium, color: Colors.white),
          ),
        ),
      ));
    }
  }

  return CustomPopupMenu(
    controller: customPopupMenuController,
    barrierColor: Colors.transparent,
    enablePassEvent: false,
    menuBuilder: () {
      return Container(
        decoration: BoxDecoration(
          color: colorFEFEFE,
          borderRadius: BorderRadius.all(Radius.circular(4.r)),
        ),
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: children,
        ),
      );
    },
    arrowColor: colorFEFEFE,
    pressType: PressType.longPress,
    child: child,
  );
}
